package com.wanli.storemobile.homepage.adapter;

import android.content.Context;
import android.text.TextUtils;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;

import com.wanli.storemobile.R;
import com.wanli.storemobile.bean.BankInfoBean;
import com.wanli.storemobile.bean.StoreListBean;

import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;

/**
 * Author: HWC
 * Description: 消息列表
 */
public class HomeStoreListAdapter extends RecyclerView.Adapter<HomeStoreListAdapter.ViewHolder> {

    private List<StoreListBean.DataBean.ItemListBean> listsBeans;
    private Context context;
    private onCallBackListener onCallBackListener;

    public HomeStoreListAdapter(List<StoreListBean.DataBean.ItemListBean> listsBeans) {
        this.listsBeans = listsBeans;
    }

    public void setOnCallBackListener(HomeStoreListAdapter.onCallBackListener onCallBackListener) {
        this.onCallBackListener = onCallBackListener;
    }


    @NonNull
    @Override
    public ViewHolder onCreateViewHolder(@NonNull ViewGroup viewGroup, int viewType) {
        context = viewGroup.getContext();
        View inflate = LayoutInflater.from(context).inflate(R.layout.item_home_store_list, viewGroup, false);
        ViewHolder viewHolder = new ViewHolder(inflate);
        return viewHolder;
    }

    @Override
    public void onBindViewHolder(@NonNull ViewHolder holder, int position) {
        StoreListBean.DataBean.ItemListBean dataBean = listsBeans.get(position);
        holder.tvStoreName.setText(dataBean.getName());

        int pay_channel_status = dataBean.getPay_channel_status();
        if (pay_channel_status == 0) {
            holder.tvStoreStatus.setText("未提交商户资料");
        } else if (pay_channel_status == 1 || pay_channel_status == 2 || pay_channel_status == 5) {
            holder.tvStoreStatus.setText("等待审核");
        } else if (pay_channel_status == 3) {
            holder.tvStoreStatus.setText("审核成功");
        } else if (pay_channel_status == 4) {
            holder.tvStoreStatus.setText("审核未通过");
        } else {
            holder.tvStoreStatus.setText("");
        }
        if (!TextUtils.isEmpty(dataBean.getReject_msg())) {
            holder.tvFeedback.setText("审核反馈：" + dataBean.getReject_msg());
        } else {
            holder.tvFeedback.setText("审核反馈：");
        }

        holder.itemView.setOnClickListener(v -> {
            onCallBackListener.onCallBack(position);
        });
    }

    @Override
    public int getItemCount() {
        return listsBeans.size() == 0 ? 0 : listsBeans.size();
    }

    public class ViewHolder extends RecyclerView.ViewHolder {


        @BindView(R.id.tv_store_name)
        TextView tvStoreName;
        @BindView(R.id.tv_store_status)
        TextView tvStoreStatus;
        @BindView(R.id.tv_feedback)
        TextView tvFeedback;

        public ViewHolder(@NonNull View itemView) {
            super(itemView);
            ButterKnife.bind(this, itemView);
        }
    }

    public interface onCallBackListener {
        void onCallBack(int position);
    }
}
